﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;

public class WindowManager : MonoBehaviour
{
	public static WindowManager instance;
	public List<WindowModule> listWindows;
	public Image fadeImg;
	WindowModule openningWindow;

	void Awake ()
	{
		instance = this;
	}

	public static void OpenWindow (WindowName name)
	{
		instance.fadeImg.DOFade (1, 0.5F).SetUpdate (true).OnComplete (() => {
			WindowModule wd = GetWindowByName (name);
			if (wd != null) {
				if (instance.openningWindow != null) {
					instance.openningWindow.obj.SetActive (false);
				}
				wd.obj.SetActive (true);
				instance.openningWindow = wd;
			}
			instance.fadeImg.DOFade (0, 0.5F).SetUpdate (true);
		});

	}



	public static WindowModule GetWindowByName (WindowName name)
	{
		for (int i = 0; i < instance.listWindows.Count; i++) {
			WindowModule wd = instance.listWindows [i];
			if (wd.name == name) {
				return wd;
			}
		}
		return null;
	}

}

[System.Serializable]
public class WindowModule
{
	public WindowName name;
	public GameObject obj;
}

public enum WindowName
{
	GW_MENU,
	GW_SELECT_LEVEL,
	GW_PLAY
}